home *** CD-ROM | disk | FTP | other *** search
- //
- // MiscDictionary.m -- HashTable subclass set up for unique string to
- // object key/value pairs. Access via HashTable methods.
- // Written by Don Yacktman Copyright (c) 1994 by Don Yacktman.
- // Version 1.0. All rights reserved.
- //
- // This notice may not be removed from this source code.
- //
- // This object is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- // This HashTable expects a MiscString as the key and any object as
- // the value. Storage of keys is actually with NXAtoms, but all methods
- // with keys are overridden in order to hide this fact so you don't have
- // to deal with it.
-
- #import <misckit/misckit.h>
-
- // Initial capacity of new MiscDictionary objects
- #define MISCDICTCAP 512 // you may need this a lot larger.
- // BUG: for some reason, the HashTable hasn't been automatically increasing
- // it's capacity, giving me segmentation faults instead. Make sure that this
- // initial capacity is big enough to suit your needs...as long as it is big
- // enough, everything works as it should. This shouldn't be at all needed,
- // since I should be able to init with cap. zero and have it grow as keys
- // are added, but it always crashes in this way, more or less:
- // #0 0x50069cc in objc_msgSend ()
- // #1 0x3fffae4 in ?? ()
- // #2 0x500b214 in -[HashTable insertKey:value:] ()
- // #3 0x110ca in -[MiscDictionary insertKey:value:] ()
- // #4 0x5cba in -[MiscDictionary(TableParse) parseFromASCIIStream:] ()
- // #5 0x5898 in MiscParseTableStream ()
- // #6 0x57bc in MiscParseTableFile ()
- // #7 0x31de in main () at test.m:7
-
- @implementation MiscDictionary
-
- - initKeyDesc: (const char *)aKeyDesc
- {
- fprintf(stderr, "MiscDictionary -initKeyDesc: called. Unexpected things may happen!\n");
- return [self init];
- }
-
- - initKeyDesc:(const char *)aKeyDesc valueDesc:(const char *)aValueDesc
- {
- fprintf(stderr, "MiscDictionary -initKeyDesc:valueDesc: called. Unexpected things may happen!\n");
- return [self init];
- }
-
- - initKeyDesc: (const char *) aKeyDesc valueDesc: (const char *) aValueDesc
- capacity: (unsigned) aCapacity
- {
- fprintf(stderr, "MiscDictionary -initKeyDesc:valueDesc:capacity: called.\nUnexpected things may happen!\n");
- return [self init];
- }
-
- - initCapacity:(int)aCap
- {
- return [super initKeyDesc:"%" valueDesc:"@" capacity:aCap];
- }
-
- - init
- {
- return [self initCapacity:MISCDICTCAP];
- }
-
- - (BOOL)isKey:(const void *)aKey
- {
- return [super isKey:[(id)aKey uniqueStringValue]];
- }
-
- - (void *)valueForKey:(const void *)aKey
- {
- return [super valueForKey:[(id)aKey uniqueStringValue]];
- }
-
- - (void *)insertKey:(const void *)aKey value:(void *)aValue
- {
- return [super insertKey:[(id)aKey uniqueStringValue] value:aValue];
- }
-
- - (void *)removeKey:(const void *)aKey
- {
- return [super removeKey:[(id)aKey uniqueStringValue]];
- }
-
- - (BOOL)nextState:(NXHashState *)aState key:(const void **)aKey
- value:(void **)aValue
- { // the table is using NXAtoms, but we cover and return MiscStrings.
- static id retString = nil;
- static void *value;
- const void *key;
- BOOL ret = [super nextState:aState key:&key value:&value];
- if (!retString) retString = [MiscString new];
- [retString setStringValue:key];
- *aValue = value;
- *aKey = retString;
- return ret;
- }
-
- @end